$(function () {
	var url = location.search; //获取url中"?"符后的字串
	//当前页面手工测试任务的id
	addManualId = ""; 
	//当前用户名
	userName = "";
	//开始录制成功后返回的操作序列id
	czxlid ="";
	//0测试中如果不点击开始录制，所有其他按钮不可点击；1没有开始录制按，并且所有操作不记录
	actionType = "";
    if (url.indexOf("?") != -1) {   
       var str = url.substr(1);   
       path = location.host;
       strs = str.split("&");   
       console.log(strs);
       addManualId = strs[0].split("=")[1];
       userName = strs[1].split("=")[1];
       roleType = Number(strs[2].split('=')[1]);
       platformId = strs[3].split('=')[1];
       platformName = decodeURI((strs[4].split('=')[1]),'UTF-8');
       if(strs[5]){
    	   actionType = strs[5].split("=")[1];
       }
    }  
    //isMainScoket 操作者时为true,访客为false
    //isSimulat 1：手动测试，2：仿真测试
    //roleType 0:仿真测试，1:访客和回放，2:手动测试操作者，3：手动测试回放
    isMainScoket = false;
    isSimulat = 1;
    //当为手动测试和仿真测试时为可以编辑操作,访客和回放不可以操作
    if(roleType == 0 || roleType == 2){
    	isMainScoket = true;
    }else{
    	isMainScoket = false;
    }
    //roleType 0:仿真测试，2:手动测试
    if(roleType == 0 || roleType == 1){
    	isSimulat = 2;
    }else if(roleType == 2 || roleType == 3){
    	isSimulat = 1;
    }
	// 全局变量websocket
	getAllDataWebSocket = "";
	
	//默认色灯处于运行状态
	$("#run").css("color", "#61F161"); 
	//默认右侧属性使用复杂模式
	$(".propertySettings").load("../../textcommon/html/simpleProperty.html",null,htmlComplete);
	curruntDeng = "";
	//所有跟踪项
	followItems = [];
	//数据换装是否完成标志
	setSJHZBool = false;
	//选择车型是否完成标志
	setXZCXBool = false;
	//是否设置跟踪项
	setGGBool = false;
	//是否停止录制
	setStopLZBool = false;
	//默认选择端别是I端
	selectXiBieBool = false;
	//默认选择的AB是A
	showImageBool = false;
	dmiDialog = null;
	gGitmes = "";
	//dmi按钮的监听
	DMIBtnInit();
	//重连时间计时器
	reTimer = null;
	//重连次数
	reConnectCount = 0;
	//是否添加加载动画
	addLoadingBool = true;
	//输入文本框的复杂与简单切换的存储
	completxAndSimpleArray = [];
	//checkbox的复杂与简单切换的存储
	completxAndSimpleChekcArray = [];
	//select的复杂与简单切换的存储
	completxAndSimpleSelectArray = [];
	//色灯的简单与复杂的切换存储
	dengObj = null;
	//右侧属性区域默认为复杂模式complex
	moudle = ""; 
	//请求lkj数据的计时器
	getLKJTimer = null;
	//是否需要请求获取LKJ数据
	getLKJStatuBool = false;
	//发送心跳包计时器
	connectTimer = null;
	//记录输入框1s间隔的计时器
	checkInputTimer = null;
	//请求语音计时器
	getVoiceTimer = null;
	//当前语音的编号
	currentVoiceNum = 0;
	//记录当前播放语音编号,为了实现播放一次的语音的之间添加一秒间隔
	currentVoiceNumCopy = 0;
	//记录当前音效播放次数
	currentPlayTimes = 0;
	//记录当前音效信息
	currentVoiceData = null;
	versionChangeWebSocket= null;
	//数据换装中记录所有进度条是否完成
	sjhzCompleteArray = [];
	//当前是否正在换装中，当换装中时，不可以点击关闭和确定按钮 -1:未换装,0:换装中,1:换装完成
	sjhzState = -1;
	//数据换装获取的数据
	sjhzDataArray = [];
	//操作脚本记录
	allActionScript = [];
	//当前选择文件换装的id
	allSelectHZArray = [];
	//换装文件类型
	allHZTypeArray = [8,9,10,24];
	// 拿到手工测试任务ID
	getManualId(); 
	//获取下拉菜单中的参数发送给后台
	getOption(); 
	//监听窗口关闭或页面刷新事件，当窗口关闭或页面刷新时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
	window.onbeforeunload = function () {
		ajaxClose();
	};
});
function DMIBtnInit(){
	$('#manualtest-disall').click(function () {
		getAllDataWebSocket.send("disAll:true");
		manualtestImageShow();
		console.log("send 四屏显示 disAll:true");
	});
	$('#manualtest-disall').mouseover(function(e){
		$('body').append("<div id='div_toop'>DMI四屏显示</div>");
		$('#div_toop').css({
			'top':"10px",
			'position':'absolute',
			'left':(e.pageX - 135) + "px",
			'background':'#777',
		    'width': '100px',
		    'text-align': 'center',
		    'border-radius': '4px 4px 4px 4px'
		});
	});
	$('#manualtest-disall').mouseout(function(){
		$('#div_toop').remove();
	});
	$('#manualtest-disall').mouseover(function(e){
		$('#div_toop').css({
			'top':"10px",
			'position':'absolute',
			'left':(e.pageX - 135) + "px",
			'background':'#777',
			'width': '100px',
		    'text-align': 'center',
		    'border-radius': '4px 4px 4px 4px'
		});
	});
	
	//ic卡点击
	$('.IcGroove').click(function(){
		BootstrapDialog.show({
		      title: '揭示文件',
		        message: $("<form class='form-inline' style='height:70px'></form>").load('../../textcommon/html/icGroovDetail.html')  ,
		        onshown:function(){
		        	icGrooveData();
		        },
		        buttons : [ {
					icon : 'glyphicon glyphicon-check',
					label : '确定',
					cssClass : 'btn-primary',
					autospin : true,
					action : function(dialogRef) {
						var value = $("#icGrooId").find('option:selected')[0].value;
						if(value == 0){
							var info = "<div style='color:black;'>请选择揭示文件！</div>";
							danger(info);
							return;
						}
						$.ajax({
							type : "POST",
							url : "../../../manualTest/sendICJieShi",
							dataType : "json",
							data : {
								"platformId" : platformId,
								"fileId":value
							},
							success : function(data) {
								if (data.flag == "0") {
									var content = "操作成功!";
									success("<div style='color:black;'>"+content+"</div>");
								} else {
									var info = "<div style='color:black;'>"+data.errorInfo+"</div>";
									danger(info);
								}
							}
						});
						dialogRef.close();
					}
				}, {
					label : '取消',
					action : function(dialogRef) {
						dialogRef.close();
					}
				} ]
		    });
	});
}
//点击ic卡的界面的数据刷新id填1，揭示文件type=24,车载数据文件type=9,运行组织文件type=10
function icGrooveData(){
	$.ajax({
		url : "../../../LKJSoftwareVersion/getVersionName",
		type : "post",
		data : {
			"sId" : 1,
			"type" : 24
		},
		dataType : "json",
		success:function(data){
			if(data.flag == 0){
				$('#icGrooId').append(new Option("请选择",0));
				for(var i = 0;i<data.content.length;i++){
					$('#icGrooId').append(new Option(data.content[i].VERSION_NAME,data.content[i].VERSION_ID));
				}
			}else{
				danger("<div style='color:black;'>"+data.errorInfo+"</div>");
			}
		},
		error:function(){
			danger("<div style='color:black;'>"+"服务端异常"+"</div>");
		}
	});
}

//从测试序列界面的链接路径中截取ID
function getManualId() {
	$('#manual-test-platform-name').text(platformName);
	if(roleType == 0 || roleType == 2){//操作者时才初始化平台数据
		addLoading();
		platformStatus = roleType == 0?3:2;
		updateTaskPlatform(platformId,addManualId,platformStatus);
		//0测试中如果不点击开始录制，所有其他按钮不可点击；1没有开始录制按，并且所有操作不记录
		if(actionType == "0"){
			//添加禁用I/II端切换A/B机切换
			$('#XiBieLight').remove();
			$('#manualtest-disall').remove();
			$('#ablight').remove();
			$('#icCard').remove();
			MaskIt("#autoMaticTesting");
			$(".divMask").css("width",$(document).width());
			updateLZButtonState();
		}else{
			$(".logButtonDiv").css("display","none");
		}
	}else{//访客和回放
		MaskIt("#allcontent");
		initWs(path);
	}
}




$("#imageDisplay").click(function () { // 获取图片当前点击位置的坐标
	var x = event.offsetX;
	var y = event.offsetY;
	sendKey(null, 2, 0, x, y); //发送点击的位置坐标给后台
});
// 页面左侧的30个按键的功能函数
function sendKey(th, KeyType, KeyValue, KeyPositionX, KeyPositionY) { // 向后台发送点击坐标位置或者按钮的键值
	var divs = $(".oneButton div"); // 下边的21个按钮
	for (var i = 0; i < divs.length; i++) {
		divs[i].style.border = "1px solid white";
	}
	var btns = $(".menuSettingKey button"); // 右侧的菜单按钮
	for (var j = 0; j < btns.length; j++) {
		btns[j].style.border = "1px solid white";
		$(".warning").css("border", "1px solid white");
	}
	if (th !== null) {
		th.style.border = "1px solid #26C254"; // 点击的按钮边框变色
	}
	//console.log(KeyType, KeyValue, KeyPositionX, KeyPositionY);
	var str = "{KeyType:" + KeyType + ",KeyValue:" + KeyValue +
		",KeyPositionX:" + KeyPositionX + ",KeyPositionY:" + KeyPositionY +
		"}";
	if (th !== null) {
		if($(th).attr("id") == "XiBieLight"){
			var duan = "";
			if(!selectXiBieBool){
				duan = 'I 端';
			}else{
				duan = 'II 端';
			}
			ajaxSend(str, 2,$(th).attr("id"),duan);
		}else{
			ajaxSend(str, 2,$(th).attr("id"),"选中");
		}
		
	}else{//点击图片坐标需要特殊处理
		ajaxSend(str, 2,"imageDisplay","("+KeyPositionX+"," +KeyPositionY+")");
	}
}
//按键及信号信息发送ajax
function ajaxSend(str, strName, id, value) {
	$.ajax({
		"url": "../../../manualTest/sendKeyOrSignal",
		"type": "post",
		"data": {
			"type": strName,
			"platformId": platformId,
			"value": str
		},
		"success": function (result) {
			if (result.flag == 0) {
				//操作日志
				addSimulationManualLog("发送成功！", 1, id, value);
			} else {
				//操作日志
				addSimulationManualLog(result.errorInfo, 0, id, value);
			}
		},
		"error": function () {
			//操作日志
			addSimulationManualLog("仿真测试连接错误！", 0, event.target.id, event.target.value);
		}
	});
}

function sendTestSignal(destination, signalType, signalValue, id, value) { // 页面右侧的属性值发送后台的功能
	var str = "{destination:" + destination + ",signalType:" + signalType +
		",signalValue:" + signalValue + "}";
	ajaxSend(str, 1, id, value);
}

function onInput(destination, signalType, event) { // input值发生变化时，获取最新的值
	//当文本框输入时，重置计时器
	if(checkInputTimer){
		clearTimeout(checkInputTimer);
	}
	//1s之内没有再输入命令时，发送指令
	checkInputTimer = setTimeout(checkInputFun(destination, signalType, event), 1000);
}

function checkInputFun(destination, signalType, event){
	return function(){
		checkInputShowFun(destination, signalType, event);
	};
}
function checkInputShowFun(destination, signalType, event){
	//当输入框的输入内容不在有效范围内，则提示重新输入
	if (Number(event.target.value) > Number(event.target.max) || Number(event.target.value) < Number(event.target.min)
			|| event.target.value=="") {
		return false;
	}
	var value = event.target.value;
	event.target.defaultValue = value;
	sendTestSignal(destination, signalType, value, event.target.id, event.target.value);
	//记录输入框的数据
	completxAndSimpleFun(signalType,destination,value,event.target.id);
	//复杂模式中，速度改变值，其他的速度也变
	if(event.target.id == "MANIputStorageId11"){
		$('.departmentSpeed').find('input').val(value);
	}
}

function getOption() { // 获取制式,方向,信号灯内的option内容
	// 每次点击平调运行时，先清空标签
	$(".fxone").empty();
	$(".fxtwo").empty();
	$(".fxthree").empty();
	$(".zsone").empty();
	$(".zstwo").empty();
	$(".zsthree").empty();
	// 加入默认的option
	$(".fxone").append("<option></option>");
	$(".fxtwo").append("<option></option>");
	$(".fxthree").append("<option></option>");
	$(".zsone").append("<option></option>");
	$(".zstwo").append("<option></option>");
	$(".zsthree").append("<option></option>");
	$.ajax({
		"url": "../../../manualTest/getManualTestDicList",
		"type": "post",
		"data": {},
		"success": function (result) {
			var data = result.content;
			if (data[0][0].dictValue == "008") {
				var fx = data[0];
				var fxone = $(".fxone"); // 一系方向
				var fxtwo = $(".fxtwo"); // 二系方向
				for (var i = 0; i < fx.length; i++) {
					fxone.append($("<option signalType='" + 42 +
							"' value="+i+
						" signalValue='" + fx[i].dictdataCode +
						"' destination='" + 1 + "'>" + fx[i].dictdataName +
						"</option>"));
					fxtwo.append($("<option signalType='" + 42 +
							"' value="+i+
						" signalValue='" + fx[i].dictdataCode +
						"' destination='" + 2 + "'>" + fx[i].dictdataName +
						"</option>"));
					$(".fxthree").append($("<option signalType='" + 42 +
							"' value="+i+
							" signalValue='" + fx[i].dictdataCode +
							"' destination='" + 3 + "'>" + fx[i].dictdataName +
							"</option>"));
				}
			}
			if (data[1][0].dictValue == "009") {
				var zs = data[1];
				var zsone = $(".zsone"); // 一系制式
				var zstwo = $(".zstwo"); // 二系制式
				for (var i = 0; i < zs.length; i++) {
					zsone.append($("<option signalType='" + 41 +
							"' value="+i+
						" signalValue='" + zs[i].dictdataCode +
						"' destination='" + 1 + "'>" + zs[i].dictdataName +
						"</option>"));
					zstwo.append($("<option signalType='" + 41 +
							"' value="+i+
						" signalValue='" + zs[i].dictdataCode +
						"' destination='" + 2 + "'>" + zs[i].dictdataName +
						"</option>"));
					$(".zsthree").append($("<option signalType='" + 41 +
							"' value="+i+
							" signalValue='" + zs[i].dictdataCode +
							"' destination='" + 3 + "'>" + zs[i].dictdataName +
							"</option>"));
				}
			}
			if (data[2][0].dictValue == "023") {
				var deng = data[2];
				var dengone = $(".dengone"); // 一系灯
				var dengtwo = $(".dengtwo"); // 二系灯
				for (var i = 0; i < deng.length; i++) {
					dengone.append($("<option signalType='" + 51 +
						"' signalValue='" + deng[i].dictdataCode +
						"' destination='" + 1 + "'>" +
						deng[i].dictdataName + "</option>"));
					dengtwo.append($("<option signalType='" + 51 +
						"' signalValue='" + deng[i].dictdataCode +
						"' destination='" + 2 + "'>" +
						deng[i].dictdataName + "</option>"));
				}
			}
			if (data[3][0].dictValue == "011") { //平调模式色灯展示
				var deng = data[3];
				var dengone = $(".dengone"); // 一系灯
				var dengtwo = $(".dengtwo"); // 二系灯
				if ($(".switchInput").find("#linghtsTwo").length !== 0) {
					$(".dengone").empty();
					$(".dengtwo").empty();
					$(".dengone").append("<option></option>");
					$(".dengtwo").append("<option></option>");
					for (var i = 0; i < deng.length; i++) {
						dengone.append($("<option signalType='" + 52 +
							"' signalValue='" + deng[i].dictdataCode +
							"' destination='" + 1 + "'>" +
							deng[i].dictdataName + "</option>"));
						dengtwo.append($("<option signalType='" + 52 +
							"' signalValue='" + deng[i].dictdataCode +
							"' destination='" + 2 + "'>" +
							deng[i].dictdataName + "</option>"));
					}
				}
				if ($(".buttonLinght").find("#btns").length !== 0) { //简易属性模式内的平调中的30个按钮
					$("#btns").empty();
					$("#btns").append("<fieldset class='pdsingal'><legend align='left'>平调信号</legend></fieldset>");
					for (var i = 0; i < deng.length; i++) {
						$("#btns .pdsingal").append($("<button onclick='btnsparameter(this)' signalType='" + 52 +
							"' signalValue='" + deng[i].dictdataCode +
							"' id='pingdiaoxinhao" + i +
							"' destination='" + 3 + "'>" +
							deng[i].dictdataName + "</button>"));
					}
				}

				//获取本地存储的历史点击按钮，设置按钮状态
				var pingdiaoID = localStorage.getItem('pingdiaoclickstorage');
				$("#btns button").css("border", "1px solid #FFF"); //点击的Button边框变色
				$("#btns button").css("color", "rgb(255, 255, 255)"); //重置button字颜色为白色
				$('#' + pingdiaoID).css("border", "1px solid rgb(38, 194, 84)");
				$('#' + pingdiaoID).css("color", "rgb(38, 194, 84)"); //点击的Button字色
			}
			
			changeComOrSimFun();
		}
	});
}
//下拉框選中變化方法
function optionChange(event) { // 制式，方向，信号灯的三个下拉框选中
	var name = event.className; //下拉框的类名
	if ($(".switchInput").find(".colorLights").length !== 0) { //平调模式不需要变灯的颜色
		var code = $("." + name + " option:selected").attr("signalvalue");
		setLightColor(code, name);
		
		//色灯的简单与复杂的切换存储
		if($("." + name + " option:selected").attr("destination") != 2){
			dengObj = {signalvalue:code,signaltype:$("." + name + " option:selected").attr("signaltype"),
					value:$("." + name + " option:selected").val()};
		}
	}
	if ($("." + name + " option:selected").attr("destination") !== undefined) { // 排除第一个空选项
		var destination = $("." + name + " option:selected").attr("destination");
		var signalType = $("." + name + " option:selected").attr("signalType");
		var signalValue = $("." + name + " option:selected").attr("signalValue");
		sendTestSignal(destination, signalType, signalValue, name, $("." + name + " option:selected").val()); // 数据发送到后台
		completxAndSimpleSelectFun(name,$("." + name + " option:selected")[0].index);
	} else {
		return false;
	}
}


/**
 * 发送复选框信息
 * @param {} current 
 */
function getCheckbox(current) { // 获取复选框的键值对发送到后台
	var name = current.className;
	var mode=$(".menuImage").attr("data");
	var destination = current.getAttribute("destination");
	var signalType = current.getAttribute("signalType");
	if(mode=="simple"){
		//如果是简单页面,选中则发110,否则0
		if (current.checked == true) { // 如果是选中状态
			sendTestSignal(destination, signalType, 110, name, "选中"); // 数据发送到后台
		} else {
			sendTestSignal(destination, signalType, 0, name, "未选中"); // 数据发送到后台
		}
	}else if(mode=="complex"){
		//如果是复杂页面,那么选中则发送input中的值,位选中则发0
		if (current.checked == true) { // 如果是选中状态
			var voltage=$('#MANIputStorageId404').val();//工况电压值
			sendTestSignal(destination, signalType, voltage, name, "选中"); // 数据发送到后台
		} else {
			sendTestSignal(destination, signalType, 0, name, "未选中"); // 数据发送到后台
		}
	}
	
	completxAndSimpleCheckBoxFun(signalType,destination,current.checked);
}


function switchLinght() { //点击运行，平调区域，切换色灯的显示方法
	//为了实现从BTM切换时，默认为简单模式
	$(".menuImage").attr("data", "simple");
	getLKJStatuBool = false;//此时不需要LKJ获取数据计时器
	$("#runningFlat").css("border", "1px solid green");
	$("#runningFlat").css("background", "#556B2F"); //点击的圆形变色
	//复杂属性的平调运行切换效果
	if ($(".switchInput").find(".colorLights").length !== 0) {
		$(".switchInput").empty(); //清空色灯区域，放入下拉框
		$("#run").css("color", "white");
		$("#flat").css("color", "#61F161"); //显示平调的灯
		$(".switchInput").load("../../textcommon/html/manualTestPageLinghtTwo.html");
		getOption(); //重新加载灯内的选项参数 

	} else if ($(".switchInput").find("#linghtsTwo").length !== 0) {
		$(".switchInput").empty(); //清空色灯区域，放入下拉框
		$("#run").css("color", "#61F161");
		$("#flat").css("color", "white"); //显示运行的灯
		$(".switchInput").load("../../textcommon/html/manualTestPageLinghtOne.html");
		getOption(); //重新加载灯内的选项参数
	}
	//简单属性模式的平调和运行切换效果
	// 如果是色灯按钮样式
	else if ($(".buttonLinght").find("#btns").length !== 0) { //色灯信号 
		$(".buttonLinght").empty();
		$("#run").css("color", "#61F161");
		$("#flat").css("color", "white"); //显示运行的灯
		$(".buttonLinght").load("../../textcommon/html/easyMoudleLinghtOne.html");
		$("#sedengs .condition #radio").css("margin-bottom", "74px");
		return false;
	} else if ($(".buttonLinght").find(".leftLinght").length !== 0) { //平调信号
		$(".buttonLinght").empty();
		$("#run").css("color", "white");
		$("#flat").css("color", "#61F161"); //显示运行的灯
		$(".buttonLinght").append("<div id='btns'></div>");
		$("#sedengs .condition #radio").css("margin-bottom", "96px");
		getOption(); //重新加载灯内的选项参数
	}

}

function moudleSwitch() { //点击浏览器图标，切换右侧属性区域的复杂和简单模式
	moudle = $(".menuImage").attr("data"); // 右侧属性区域默认为复杂模式complex
	//切换前的处理
	preDeel();
	if (moudle == "complex") { //右侧属性切换为复杂模式
		if ($(".propertySettings").find(".signalings").length !== 0 || $(".propertySettings").find("styele").length == 0) {
			$(".propertySettings").empty(); //清空右侧属性值区域
			$(".propertySettings").load("../../textcommon/html/complexProperties.html",null,htmlComplete);
			$(".menuImage").attr("data", "simple");
			getOption(); //重新加载灯内的选项参数
			$(".buttonLinght").load("../../textcommon/html/easyMoudleLinghtOne.html");
		}
		getLKJStatuBool = false;//此时不需要LKJ获取数据计时器
		return false;
	} else if (moudle == "simple") { //右侧属性切换为简单模式
		getLKJStatuBool = true;//此时需要LKJ获取数据计时器
		if ($(".propertySettings").find("#leftOne").length !== 0 || $(".propertySettings").find("styele").length == 0) {
			$(".propertySettings").empty(); //清空右侧属性值区域
			$(".propertySettings").load("../../textcommon/html/simpleProperty.html",null,htmlComplete);
			$(".menuImage").attr("data", "complex");
			getOption(); //重新加载灯内的选项参数
		}
	}
}
// 简单属性模式内的平调模式中的30个按钮点击传递参数
function btnsparameter(th) {
	$("#btns button").css("border", "1px solid #FFF"); //点击的Button边框变色
	$("#btns button").css("color", "rgb(255, 255, 255)"); //重置button字颜色为白色
	$(th).css("border", "1px solid rgb(38, 194, 84)");
	$(th).css("color", "rgb(38, 194, 84)"); //点击的Button字变色
	var signalValue = ($(th).attr("signalValue"));
	var signalType = ($(th).attr("signalType"));
	var destination = ($(th).attr("destination"));
	sendTestSignal(destination, signalType, signalValue, ($(th).attr("id")), "选中 " + $(th).html()); //发送到后台

	//存储点击的第一个按钮到本地
	localStorage.setItem('pingdiaoclickstorage', ($(th).attr("id")));
}
// 简单属性模式下点击按钮更换色灯图片并同时发送1,2系参数
function linghts(th, destination, signalType, signalValue) {
	var data = $(th).attr("data");
	var bool = true; //色灯是否亮起
	if (curruntDeng != signalValue) {
		$(".rightButton button").css("border", "1px solid #FFF");
		$(".rightButton button").css("color", "rgb(255, 255, 255)"); //重置button字颜色为白色
		$(th).css("border", "1px solid rgb(38, 194, 84)"); //点击的Button边框变色
		$(th).css("color", "rgb(38, 194, 84)"); //点击的Button字色
		sendTestSignal(destination, signalType, signalValue, $(th).attr("class"), "打开 " + $(th).html()); //发送到后台
		setLightColor(signalValue, "dengs"); //色灯变色
		$(th).attr("data", "2");
		bool = true;
	} else {
		if (data == "1") { //按钮的色灯状态
			$(".rightButton button").css("border", "1px solid #FFF");
			$(".rightButton button").css("color", "rgb(255, 255, 255)"); //重置button字颜色为白色
			$(th).css("border", "1px solid rgb(38, 194, 84)"); //点击的Button边框变色
			$(th).css("color", "rgb(38, 194, 84)"); //点击的Button字色
			sendTestSignal(destination, signalType, signalValue, $(th).attr("class"), "打开 " + $(th).html()); //发送到后台
			setLightColor(signalValue, "dengs"); //色灯变色
			$(th).attr("data", "2");
			bool = true;
		} else if (data == "2") { //按钮的灭灯状态
			$(".rightButton button").css("border", "1px solid #FFF");
			$(".rightButton button").css("color", "rgb(255, 255, 255)"); //重置button字颜色为白色
			$(th).css("border", "1px solid yellow"); //点击的Button边框变色
			sendTestSignal(3, 51, 17, $(th).attr("class"), "关闭 " + $(th).html()); //发送灭灯的键值到后台
			setLightColor(17, "dengs"); //色灯变色
			$(th).attr("data", "1");
			bool = false;
		}
	}
	
	//简单与复杂的切换存储
	if(bool){
		dengObj = {signalvalue:signalValue,signaltype:signalType};
	}else{
		dengObj = null;
	}
	curruntDeng = signalValue;

	//存储被点击的按钮id
	localStorage.setItem('RightButtonStorage', signalValue + "?" + bool);
}

//进行预处理，比如停止循环获取状态信息。
function preDeel() {
	if (window.systemStateHandle != null) {
		clearInterval(window.systemStateHandle);
	}
}
// 右侧的六个圆形设置按钮，点击更换设置界面的效果
function menuAims(moudel, th) {
	//为了实现从BTM切换时，默认为简单模式
	$(".menuImage").attr("data", "simple");
	getLKJStatuBool = false;//此时不需要LKJ获取数据计时器
	$(".nav div").css("border", "none"); //清除所有的圆形的颜色
	$(".nav div").css("background", "#313873"); //清除所有的圆形的颜色
	$(th).css("border", "1px solid green"); //点击的圆形变色
	$(th).css("background", "#556B2F"); //点击的圆形变色
	//预处理
	preDeel();
	if (moudel == "ATP") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/atp.html?platformId=" + platformId);
	} else if (moudel == "EMU") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/emu.html?platformId=" + platformId);
	} else if (moudel == "BTM") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/btm.html?platformId=" + platformId);
	} else if (moudel == "TCR") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/tcr.html?platformId=" + platformId);
	} else if (moudel == "TAX") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/tax.html?platformId=" + platformId);
	} else if (moudel == "LAIS") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/lais.html?platformId=" + platformId);
	} else if (moudel == "STA") {
		$(".propertySettings").empty(); //清空右侧属性值区域
		$(".propertySettings").load("../../textcommon/html/sta.html?platformId=" + platformId);
	}
}
// 初始化websocket
function initWs(ip) {
	var connectIp = 'ws://' + ip + '/asts/manual/testWebsocket/{'+addManualId+'}/{'+platformId+'}/{'+userName+'}/{'+isMainScoket+'}/{'+isSimulat+'}';
	console.log(connectIp);
	getAllDataWebSocket = new WebSocket(connectIp);
	getAllDataWebSocket.onmessage = function (event) {
		getAllDataWebSocketMessage(event);
	};

	getAllDataWebSocket.onerror = function (event) {
		danger("<div style='color:black;'>"+"websocket异常断开"+"</div>");
	};
	getAllDataWebSocket.onopen = function (event) {
		 var str = addManualId + "," + userName;
			getAllDataWebSocket.send(str);
	};
	getAllDataWebSocket.onclose = function (event) {
		getAllDataWebSocketClose(event);
	};
	//监听窗口关闭或页面刷新事件，当窗口关闭或页面刷新时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
	window.onbeforeunload = function () {
		ajaxClose();
	};
}
var textImage = "";
var idImage="";
// 从后台获取到所有的需要的数据，包括图片，日志信息，进度，数据。
function getAllDataWebSocketMessage(event) {
	var pojo = event.data;
	var gettype = Object.prototype.toString;
	if (gettype.call(pojo) == "[object Blob]") {//返回图片信息
		if(idImage!=""){
			loadPicture(pojo,idImage,textImage);
		}
	}else if(gettype.call(pojo) == "[object String]" && pojo.split("broadcast:")[1]){//仿真测试访客日志信息
		addManualLogNew(pojo.split("broadcast:")[1]);
	}else if(gettype.call(pojo) == "[object String]" && pojo.indexOf("testExit")>=0){//完成后测试后退出
		addAlert("测试已完成，请退出！");
		//提示操作者退出时，访客断开websocket连接
		if(getAllDataWebSocket){
			getAllDataWebSocket.close();
		}
	}else{
		var obj = eval('(' + pojo + ')');
		if(obj.operateLog){////手动测试回放日志信息
			addManualLogNew(obj.operateLog);
		}else if(obj.code>=0){//收到语音信息
			var code = obj.code;
			var time = obj.time;
			playVoice(code,time);
		}else{//图像位置信息
			var flag = obj.flag;
			if (flag == 0) { 
				textImage = obj.textImage;
				idImage = obj.id;
			} else {
				var info = obj.info;
				var content = "<span style='color:black;'>" + info + "</span>";
				BootstrapDialog.show({
					title: '提示',
					message: content,
					buttons: [{
						icon: 'glyphicon glyphicon-check',
						label: '确定',
						cssClass: 'btn-primary',
						autospin: true,
						action: function () {
							window.location.href = "../../test/html/manualTestMain.html?userName=" + userName;
						}
					}]
				});
			}
		}
	}
}



function getAllDataWebSocketClose(event) {
	 console.log("断开websocket");
	getAllDataWebSocket.close();	
}

//退出情况时需要做的处理，包括刷新退出、异常退出等
function ajaxClose() {
	if(getAllDataWebSocket){//如果有长连接，那么断开
		getAllDataWebSocket.close();
	}
	if(!isMainScoket){//当为访客和回放时没有占用平台，不需要释放平台
		return;
	}else{
		$.ajax({
			"url": "../../../manualTest/stopManualTest",
			"type": "post",
			"data": {
				 manualId: addManualId,
				 platformId:platformId
			}
		});
	}
	if(actionType == "0"&&setGGBool == true&&setStopLZBool==false){
		//已经开始未点击停止录制时刷新页面自动调用停止录制接口
		stopLuZhi();
	}
}
// 加载图片
function loadPicture(pic, id, imageText) {
	// 创建FileReader对象，该对象时html5中的特有对象，详细用法可以//参照html5相关资料
	var reader = new FileReader();
	// 设置FileReader对象的读取文件回调方法
	reader.onload = function (eve) {
		// 判断文件是否读取完成
		if (eve.target.readyState == FileReader.DONE) {
			if (showImageBool) {
				//如果显示着外部屏幕
				// 读取文件完成后，创建img标签来显示服务端传来的字节数//组
				$('#'+id).find('img').attr('src',this.result);
				$('#'+id).find('div').html(imageText);
			} else {
				//如果显示着外部屏幕
				// 读取文件完成后，创建img标签来显示服务端传来的字节数//组
				// 读取文件完成后内容放在this===当前
				// fileReader对象的result属性中，将该内容赋值img标签//浏览器就可以自动解析内容格式并且渲染在浏览器中
				$('#'+id).find('img').attr('src',this.result);
			}
		}
	};
	// 调用FileReader的readAsDataURL的方法自动就会触发onload事件
	reader.readAsDataURL(pic);
};

//显示四屏
function manualtestImageShow() {
	dmiDialog = BootstrapDialog.show({
		closable:function(){
			$(this).on('click',function(){
				showImageBool = false;
				getAllDataWebSocket.send("disAll:false");
			});
		},
		title: 'DMI四屏显示',
		message: $("<form class='form-inline' style='height:600px;width:1330px'></form>").load('../../textcommon/html/manualCellView.html'),
		onshown: function() {
			showImageBool = true;
		},
		buttons: [{
			icon: 'glyphicon glyphicon-check',
			label: '确定',
			cssClass: 'btn-primary',
			autospin: true,
			action: function(dialogRef) {
				showImageBool = false;
				getAllDataWebSocket.send("disAll:false");
				dialogRef.close();
			}
		}]
	});
}



//弹出数据软件换装界面
function changeSJFile(){
	//从后端接口获取四种软件的各个标签下的数据后弹出页面并进行页面数据初始化
	$.ajax({
		url : "../../../LKJSoftwareVersion/getDataFiles",
		type : "post",
		data : {
			"type" : 0,
			"dataFlag" : ""
		},
		dataType : "json",
		success:function(data){
			if(data.flag == 0){
				var content = data.content;
				sjhzDataArray = data.content;
			    BootstrapDialog.show({
					title: 'LKJ数据软件换装',
					closable:false,
					message: $("<form class='form-inline' style='height:180px;width:780px;'></form>").load('../../test/html/sjFileChange.html'),
					onshown: function() {
						
						//初始化换装下拉内容
						for(var i=0;i<content.length;i++){
							var id1 = "";
							var id2 = "";
							if(content[i].softwareType==8){
								id1 = "#kzcs_bq";
								id2 = "#kzcs_wj";
							}else if(content[i].softwareType==9){
								id1 = "#czsj_bq";
								id2 = "#czsj_wj";
							}else if(content[i].softwareType==10){
								id1 = "#yxjl_bq";
								id2 = "#yxjl_wj";
							}else if(content[i].softwareType==24){
								id1 = "#jssj_bq";
								id2 = "#jssj_wj";
							}
							var dataFlags = content[i].dataFlags;
							
							$(id1).append("<option></option>");
							for(var j=0;j<dataFlags.length;j++){
								var dataFlag = dataFlags[j].flagName;
								var obj = "<option>"+dataFlag+"</option>";
								$(id1).append(obj);
							}
						}
						//记录脚本
						for(var i = 0;i<allSelectHZArray.length;i++){
							addActionScript("007016",{type:allSelectHZArray[i].type+"",id:allSelectHZArray[i].id});
						}
					},
					buttons: [{
						icon: 'glyphicon glyphicon-check',
						label: '换装',
						cssClass: 'btn-primary',
						autospin: true,
						action: function(dialogRef) {
							if(sjhzState == -1){
								sjhzState = 0;
								//封装换装数据集
								var hzdata = [];
								var ids=[8,9,10,24];
								var fileIds = ["#kzcs_wj","#czsj_wj","#yxjl_wj","#jssj_wj"];
								//重置换装完成状态的数组
								sjhzCompleteArray = [];
								for(var i=0;i<4;i++){
									var fileId = $(fileIds[i]).val();
									if(fileId!=null){
										var data = {};
										data.fileId = fileId;
										if(ids[i]==24){
											data.id=ids[i]+"_1";
										}else{
											data.id=ids[i]+"_1111";
										}
										hzdata.push(data);
										sjhzCompleteArray.push(false);
									}else{
										sjhzCompleteArray.push(null);
									}
								}
								if(hzdata.length>0){
									sendLKJDataHuanZhuang(hzdata);//发送LKJ数据换装请求
								}else{//无需换装数据，此时相当于跳过换装步骤，此时选择车型按钮可以点击
									sjhzState = 1;
									setSJHZBool = true;
									updateLZButtonState();
									dialogRef.close();
								}
							}else if(sjhzState == 0){
								warning("<div style='color:black;'>"+"未完成请稍后或者已经失败请退出！"+"</div>");
								return;
							}else if(sjhzState == 1){
								sjhzState = -1;
								dialogRef.close();
							}
						}
					}]
				});
			}else{
				danger("<div style='color:black;'>"+data.errorInfo+"</div>");
			}
		},
		error:function(){
			danger("<div style='color:black;'>"+"服务器异常！"+"</div>");
		}
	});
	//选择需要使用的数据版本，点击换装按钮进行换装并返回各个软件的换装进度和结果信息（四个软件必须换），如果全部换装成功可进行下一步，否则不能进入下一步

}
//将lkj数据文件进行换装
function sendLKJDataHuanZhuang(data){
	var versionChanges = {id:platformId,softwares:JSON.stringify(data)};
	//发起换装请求
	$.ajax({
		url:'../../../SoftwareVersionChange/lkjSoftWareChange',
		type:'POST',
		traditional:true,
		contentType:"application/x-www-form-urlencoded; charset=utf-8",
		data:versionChanges,
		async:false,
		success:function(data){
			if(data.flag==0){
				var changeData = data.content;
				var changeData1 = [];
				for(var i=0;i<changeData.length;i++){
					//遍历换装请求结果
					var result = changeData[i].result;
					if(result<=0){
						var id = changeData[i].id.split("_");
						var jgid = "";
						if(id=="8"){
							jgid = "#kzcs_jg";
						}else if(id=="9"){
							jgid = "#czsj_jg";
						}else if(id=="10"){
							jgid = "#yxjl_jg";
						}else if(id=="24"){
							jgid = "#jssj_jg";
						}
						$(jgid).html("失败");
						$(jgid).css('color','#f01149');
					}else{
						changeData1.push(changeData[i]);
					}
				}
				initHZWS(JSON.stringify({id:platformId,type:'2',softwares:changeData1}));
			}else{
				danger("<div style='color:black;'>"+data.errorInfo+"</div>");
			}
		}
	});

}
//换装请求成功后，创建websocket连接，获取换装进度
function initHZWS(data){
	if (window.WebSocket) {
		// 初始化websocket链接，并发送数据，如果链接成功则将下拉框以及按钮置为不可用状态
		versionChangeWebSocket = new WebSocket('ws://' + path
				+ '/asts/versionChange');
		versionChangeWebSocket.onmessage = function(event) {
			var data = JSON.parse(event.data);// 获取到后台推送过来的数据
			// 如果result!=-1，说明有进度，那么刷新对应进度条
			if (data.result != '-1') {
				updateProgress(data);
			}
		};
		versionChangeWebSocket.onerror = function(event) {
			console.log('websocket链接异常');
			versionChangeWebSocket.close();
		};
		versionChangeWebSocket.onopen = function(event) {
			console.log('versionChangeWebSocket open');
			// websocket打开后发送信息
			versionChangeWebSocket.send(data);
			changeDisable(true);
		};
		versionChangeWebSocket.onclose = function(event) {
			changeDisable(false);
			console.log(event.reason);// 输出关闭原因
		};
	}else{
        console.log('This browser does not supports WebSocket');
    }
}

//刷新对应进度条显示
function updateProgress(data){
	var id = data.id.split("_")[0];//进度id
	var jgid = "";
	if(id=="8"){
		id="#kzcs_progress";
		jgid = "#kzcs_jg";
	}else if(id=="9"){
		id="#czsj_progress";
		jgid = "#czsj_jg";
	}else if(id=="10"){
		id="#yxjl_progress";
		jgid = "#yxjl_jg";
	}else if(id=="24"){
		id="#jssj_progress";
		jgid = "#jssj_jg";
	}
	var result = data.result.result;
	var progress = 0;//进度条进度
	var textColor = '#ede4e4';//状态文本的颜色
	var textStr = '未开始';//状态文本的显示
	switch (result) {//0失败，1进行中，2完成
		case 0:
			textColor = '#f01149';
			textStr = '失败';
			$(id).removeClass('progress-bar-success');
			$(id).addClass('progress-bar-danger');
			$(id).removeClass('active');
			break;
		case 1:
			$(id).addClass('active');
			progress = data.result.progress;
			textColor = '#4cfb32';
			textStr = '进行中...';
			$(id).css('width',progress+"%");
			$(id).html(progress+"%");
			break;
		case 2:
			$(id).removeClass('active');
			progress = data.result.progress;
			textColor = '#4cfb32';
			textStr = '完成';
			$(id).css('width',progress+"%");
			$(id).html(progress+"%");
			updateSJHZCompleteArray(data.id.split("_")[0]);
		break;
		default:
			break;
	}
	$(jgid).html(textStr);
	$(jgid).css('color',textColor);
}

//更新数据换装中进度条的状态数组
function updateSJHZCompleteArray(id){
	//当前完成进度的索引
	var index = -1;
	if(id=="8"){
		index = 0;
	}else if(id=="9"){
		index = 1;
	}else if(id=="10"){
		index = 2;
	}else if(id=="24"){
		index = 3;
	}
	sjhzCompleteArray[index] = true;
	
	//判断是否所有进度已完成
	var allBool = true;
	for(var i = 0;i<sjhzCompleteArray.length;i++){
		if(sjhzCompleteArray[i]!=null){
			if(!sjhzCompleteArray[i]){
				allBool = false;
			}
		}
	}
	
	//当所有进度完成时，说明完成了数据换装的步骤，可以进行下一步选择车型
	if(allBool){
		sjhzState = 1;
		setSJHZBool = true;
		updateLZButtonState();
		if(versionChangeWebSocket!=null){
			versionChangeWebSocket.close();
		}
		setTimeout(function() {
			BootstrapDialog.closeAll();
		}, 1000);//换装完成后一秒自动关闭换装界面
	}
}

//数据换装中select的切换联动
function onSJChange(e){
	updateSJHZData(e.id,($("#"+e.id).find('option:selected')[0].index-1));
}

//切换数据环境后，后面select修改内容
function updateSJHZData(id,selectIndex){
	var index = -1;
	var id2 = "";
	if(id == "kzcs_bq"){
		index = 0;
		id2 = "#kzcs_wj";
	}else if(id == "czsj_bq"){
		index = 1;
		id2 = "#czsj_wj";
	}else if(id == "yxjl_bq"){
		index = 2;
		id2 = "#yxjl_wj";
	}else if(id == "jssj_bq"){
		index = 3;
		id2 = "#jssj_wj";
	}
	//第一条为空数据
	if(selectIndex == -1){
		$(id2).find("option").remove();
		return;
	}
	var dataFlags = sjhzDataArray[index].dataFlags;
	var files = dataFlags[selectIndex].files;
	for(var k=0;k<files.length;k++){
		var id = files[k].id;
		var name = files[k].name;
		var file = "<option value='"+id+"'>"+name+"</option>";
		$(id2).append(file);
	}
}

//当开始换装时将右侧所有输入框置为不可用状态，之后还原为可用状态
function changeDisable(disable){
	$("select.signSelect").prop("disabled", disable);
	$("#changeBtn").prop("disabled", disable);
}
function selectCX(){
	//选择车型后调用后台接口处理并返回相应结果
	$.ajax({
		url : "../../../trainType/getTrainTypeDict",
		type : "post",
		dataType : "json",
		success:function(data){
			if(data.flag == 0){
				var content = data.content;
				BootstrapDialog.show({
					title: '选择车型',
					message: $("<form class='form-inline' style='height:80px;width:380px;'></form>").load('../../test/html/selectCX.html'),
					onshown: function() {
						//初始化车型下拉内容
						for(var i=0;i<content.length;i++){
							var trainTypes = content[i];
							var name = trainTypes.name;
							var code = trainTypes.code;
							var obj = "<option value='"+code+"'>"+name+"</option>";
							$("#lclxid").append(obj);
						}
					},
					buttons: [{
						icon: 'glyphicon glyphicon-check',
						label: '确定',
						cssClass: 'btn-primary',
						autospin: true,
						action: function(dialogRef) {
							var data = $("#lclxid").val();
							sendCXInfo(data,platformId,dialogRef);
						}
					}, {
						label: '取消',
						action: function(dialogRef) {
							dialogRef.close();
						}
					}]
				});
			}else{
				danger("<div style='color:black;'>"+data.errorInfo+"</div>");
			}
		},
		error:function(){
			danger("<div style='color:black;'>"+"服务器异常！"+"</div>");
		}
	});

}
//发送车型信息给后台做一系列操作
function sendCXInfo(data,platformId,dialogRef){
	$.ajax({
		url : "../../../trainType/doSomethingByCode",
		type : "post",
		data : {
			code : data,
			platformId :platformId
		},
		dataType : "json",
		success:function(data){
					if (data.flag == 0) {
						// 记录脚本
						sendLKJCondition(data.content);
						var errorData = JSON.parse(data.content.errorMessage);
						// 0灰1红2黄3绿<span class='simpleStatuValue'
						// style='background: green;'></span>
						// "<span class='simpleStatuValue'
						// style='margin-left:5px !important;background:
						// gray;'></span><span
						// style='margin-left:5px'>-该拆件未连接</span>"
						// +"<span class='simpleStatuValue'
						// style='margin-left:5px !important;background:
						// red;'></span><span
						// style='margin-left:5px'>-通道故障</span>"
						// +"<span class='simpleStatuValue'
						// style='margin-left:5px !important;background:
						// yellow;'></span><span
						// style='margin-left:5px'>-有通道故障，未接外设</span>"
						// +"<span class='simpleStatuValue'
						// style='margin-left:5px !important;background:
						// green;'></span><span
						// style='margin-left:5px'>-所有通道自检正常</span>"
						// console.log(errorData);
						errorDataHtml = "";
						// 处理数据生成html
						for ( var val in errorData) {
							var myColor = "gray";
							if (errorData[val] == 1) {
								myColor = "red";
							} else if (errorData[val] == 2) {
								myColor = "yellow";
							} else if (errorData[val] == 3) {
								myColor = "green";
							}
							errorDataHtml += "<span style='margin-left:25px'>"
									+ val
									+ ":</span><span class='simpleStatuValue' style='margin-left:5px !important;background: "
									+ myColor + ";'></span>";
						}
						BootstrapDialog.show({
							title : '提示',
							message : "<div style='color:black;'>"
									+ errorDataHtml + ",是否继续？</div>",
							buttons : [ {
								icon : 'glyphicon glyphicon-check',
								label : '确定',
								cssClass : 'btn-primary',
								autospin : true,
								action : function() {
									setXZCXBool = true;
									updateLZButtonState();
									BootstrapDialog.closeAll();
								}
							}, {
								label : '取消',
								action : function(dialogRef) {
									dialogRef.close();
								}
							} ]
						});
					}else{
				danger("<div style='color:black;'>"+data.errorInfo+"</div>");
			}
		},
		error:function(){
			danger("<div style='color:black;'>"+"服务器异常！"+"</div>");
		}
	});
}
//设置跟踪项按点击
function setFollow(){
	$.ajax({
		type: "POST",
		url: "../../../manualTest/getMonitorItems",
		success: function(data) {
			followItems = data.content;
			BootstrapDialog.show({
				title: '设定跟踪项',
				message: $("<form class='form-inline' style='height:400px;width:735px;overflow: auto;'></form>").load('../../textcommon/html/following.html'),
				onshown: function() {
					var htmlData="";
					for(var i = 0;i<followItems.length;i++){
						var checked = "";
						if(followItems[i].type==1){
							checked = "checked disabled ";
						}
						htmlData = htmlData + "<div class='followCell'><input type='checkbox'signalType="+
						followItems[i].code+" id='followCheckbox_"+
						i+"' "+checked+"><div class='followLabel'>"+
						followItems[i].name+"</div></div>";
					}
					$('.followDiv').html(htmlData);
				},
				buttons: [{
					icon: 'glyphicon glyphicon-check',
					label: '确定',
					cssClass: 'btn-primary',
					autospin: true,
					action: function(dialogRef) {
						sendFollowData();//发送设定跟踪项请求
					}
				}, {
					label: '取消',
					action: function(dialogRef) {
						dialogRef.close();
					}
				}]
			});
		},
		error: function(err) {
			danger("<div style='color:black;'>"+"设定跟踪项异常"+"</div>")
		}
	});
}
//发送设定跟踪项请求
function sendFollowData(){
	gGitmes = getItemsData();
	$.ajax({
		url: '../../../manualTest/startRecord',
		type: "post",
		data:{
			manualTaskId:addManualId,
			platFormId:platformId,
			items:gGitmes
		},
		success: function(obj) {
			if(obj.flag==0){
				content = "<div style='color:black;'>设置跟踪项成功！</div>";
				success(content);
				czxlid = obj.content;
				//跟踪项添加成功
				setGGBool = true;
				updateLZButtonState();
				//取消遮罩层
				unMaskIt("#autoMaticTesting");
			}else{
				var content = "<div style='color:black;'>"+obj.errorInfo+"</div>";
				danger(content);
			}
		},
		error: function(error) {
			var content = "<div style='color:black;'>"+error.errorInfo+"！</div>";
			danger(content);
		}
	});
	
}


//获取设置的跟踪项数据
function getItemsData(){
	var str = "";
	var signalType = 0;
	for(var i = 0;i<followItems.length;i++){
		if($('#followCheckbox_'+i).is(':checked')){
			signalType = $("#followCheckbox_" + i).attr("signalType");
			str = str+signalType+",";
		}
	}
	str = str.substring(0, str.length - 1);
	return str;
}

//切换系别
function changeXiBie(th){
	selectXiBieBool = !selectXiBieBool;
	if(!selectXiBieBool){
		$('.duan').html('I 端');
	}else{
		$('.duan').html('II 端');
	}
	var value= 5;
	if(!selectXiBieBool){
		value = 5;
	}else{
		value = 6;
	}
	sendKey(th, 3, value, 0, 0); //发送点击的位置坐标给后台
}
//点击A机B机
function clickAB(type,th){
	var value= 9;
	if(type == 0){
		value = 9;
		$('#AC').addClass('activeAB');
		$('#BC').removeClass('activeAB');
		$('#ALight').css('background','#00FF01');
		$('#BLight').css('background','#292929');
	}else{
		value = 10;
		$('#BC').addClass('activeAB');
		$('#AC').removeClass('activeAB');
		$('#ALight').css('background','#292929');
		$('#BLight').css('background','#00FF01');
	}
	sendKey(th, 3, value, 0, 0); //发送点击的位置坐标给后台
}
//LKJ输出状态刷新
function udpateLKJStatu(){
	if(!getLKJStatuBool){//此时不行要请求LKJ数据
		return;
	}
	$.ajax({
		type : "POST",
		url : "../../../manualTest/getLKJOutPutInfo",
		dataType : "json",
		data : {
			"platformId" : platformId
		},
		success : function(data) {
			if (data.flag == "0") {
				//console.log(data);
				var statuArray = [data.content.xieZai,data.content.jianYa,
				                  data.content.guanFeng,data.content.jinJi1,
				                  data.content.jinJi2,data.content.beiYong1,
				                  data.content.beiYong2,data.content.beiYong3,
				                  data.content.beiYong4,data.content.beiYong5];
				for(var i = 0;i<statuArray.length;i++){
					if(statuArray[i] == 0){
						$("#LKJStatuLeft"+i).css("background", "gray");
						if($("#LKJStatuRight"+i)){
							$("#LKJStatuRight"+i).css("background", "gray");
						}
					}else if(statuArray[i] == 1){
						$("#LKJStatuLeft"+i).css("background", "red");
						if($("#LKJStatuRight"+i)){
							$("#LKJStatuRight"+i).css("background", "gray");
						}
					}else if(statuArray[i] == 2){
						$("#LKJStatuLeft"+i).css("background", "gray");
						if($("#LKJStatuRight"+i)){
							$("#LKJStatuRight"+i).css("background", "green");
						}
					}else{
						$("#LKJStatuLeft"+i).css("background", "red");
						if($("#LKJStatuRight"+i)){
							$("#LKJStatuRight"+i).css("background", "green");
						}
					}
				}
				$('#MANIputStorageId400').val(data.content.szbShiSu);
				$('#MANIputStorageId401').val(data.content.szbXianSu);
				getLKJTimer = setTimeout('udpateLKJStatu()', 1000);
			} else {
				var info = "<div style='color:black;'>"+data.errorInfo+"</div>";
				danger(info);
			}
		}
	});
}
//初始化仿真平台状态
function initASTSData(platformId)
{   
	console.log("开始初始化平台");
	//记录脚本
	addActionScript("007017",{type:1});
	$.ajax({
		type : "POST",
		url : "../../../manualTest/initASTSDevice",
		dataType : "json",
		data : {
			"platformId" : platformId
		},
		success : function(data) {
			if (data.flag == "0") {
				getLKJStatuBool = true;
				console.log("初始化平台完成");
				initWs(path);
				initSendAjaxSend();
				udpateLKJStatu();
				setTimeout("removeLoading()",10000) 
			} else {
				addAlert(data.errorInfo);
			}
		},
		error:function(data){
			addAlert("初始化平台异常");
		}
	});
}

//首次进入界面，发送不为零的参数
function initSendAjaxSend() {
	console.log("发送不为零的参数");
	var inputArray = $('#leftOne').find('input');
	for(var i = 0;i<inputArray.length;i++){
		if(inputArray[i].value !='0' && inputArray[i].value !=""){
			var strInput = inputArray[i].oninput+"";
			if(strInput!="null"){
				var msgArray = strInput.split('{')[1].split('}')[0].split("(")[1].split(")")[0].split(',');
				var str = "{destination:" + msgArray[0] + ",signalType:" + msgArray[1] +
				",signalValue:" + inputArray[i].value + "}";
				initSendData(str,1);
			}
		}
	}
}
//首次进入界面，发送不为零的参数请求的接口
function initSendData(str, strName){
	$.ajax({
		"url": "../../../manualTest/sendKeyOrSignal",
		"type": "post",
		"data": {
			"type": strName,
			"platformId": platformId,
			"value": str
		},
		"success": function (result) {
			//console.log(result);
		},
		"error": function () {
			
		}
	});
}

//简单和复杂来回切换时，数据的对应关系，
//1、简单到复杂：简单的数据赋值给复杂的I 和II 系
//2、复杂到简单：复杂的I系数据赋值给简单的数据
function completxAndSimpleFun(signaltype,destination,value,id)
{
	if(destination == 2 || (signaltype>=11 && signaltype<=14)){//II系的数据不用记录
		if(signaltype == 1){
			
		}
		return;
	}
	var isBool = false;//判断当前是否已经存储当前的属性对应的数据
	var index = 0;
	for(var i = 0;i<completxAndSimpleArray.length;i++){
		if(signaltype == completxAndSimpleArray[i].signaltype){
			isBool = true;
			index = i;
			break;
		}
	}
	if(signaltype != 1){
		if(!isBool){
			completxAndSimpleArray.push({signaltype:signaltype,value:value});
		}else{
			completxAndSimpleArray[index].value = value;
		}
	}else{//速度的复杂与简单的切换
		if(id == "MANIputStorageId402" || id == "MANIputStorageId11"){//简单界面的记录
			if(!isBool){
				completxAndSimpleArray.push({signaltype:"1",value:value});
			}else{
				completxAndSimpleArray[index].value = value;
			}
		}
	}
}

//切换到复杂界面的时候的数据处理
function htmlComplete(){
	//对监听输入框的最大值和最小值输入
	addListenerEventFun();
	var inputArray = $('.propertySettings').find('input');
	for(var j = 0;j<completxAndSimpleArray.length;j++){
		for(var i = 0;i<inputArray.length;i++){
			if(inputArray[i].oninput){
				var strInput = inputArray[i].oninput+"";
				var msgArray = strInput.split('{')[1].split('}')[0].split("(")[1].split(")")[0].split(',');
				var signaltype = msgArray[1];
				if(signaltype == 32 || signaltype == 2){//双针表速度和电流没有对应的复杂和简单切换
					continue;
				}
				if(completxAndSimpleArray[j].signaltype == signaltype){
					$('#'+inputArray[i].id).val(completxAndSimpleArray[j].value);
					if(signaltype == 1){//速度的值和其他8个的速度值同时变化
						$('.departmentSpeed').find('input').val(completxAndSimpleArray[j].value);
					}
				}
			}
		}
	}
	var checkboxArray = $('.propertySettings').find('input');
	for(var p = 0;p<completxAndSimpleChekcArray.length;p++){
		for(var q = 0;q<checkboxArray.length;q++){
			if(checkboxArray[q].type =="checkbox"){
				if(completxAndSimpleChekcArray[p].signalType == checkboxArray[q].getAttribute("signaltype")){
					$('.'+checkboxArray[q].getAttribute("class")).attr('checked',completxAndSimpleChekcArray[p].checked);
				}
			}
		}
	}
	
	udpateLKJStatu();//更新显示LKJ状态
}
//多选框的复杂和简单的切换的逻辑的处理
function completxAndSimpleCheckBoxFun(signalType,destination,checkBool){
	if(destination == 2){
		return;
	}
	var bool = false;
	var index = 0;
	for(var i = 0;i<completxAndSimpleChekcArray.length;i++){
		if(completxAndSimpleChekcArray[i].signalType == signalType){
			bool = true;
			index = i;
			break;
		}
	}
	
	if(bool){
		completxAndSimpleChekcArray[index].checked = checkBool;
	}else{
		completxAndSimpleChekcArray.push({signalType:signalType,checked:checkBool});
	}
}

//select的复杂到简单的存储
function completxAndSimpleSelectFun(name,value){
	if(name == "zstwo" || name == "fxtwo"){
		return;
	}
	var valueName  ="";
	if(name == "zsone" || name == "zsthree"){
		valueName = "ZS";
	}else{
		valueName = "FX";
	}
	var bool = false;
	var index = 0;
	for(var i = 0;i<completxAndSimpleSelectArray.length;i++){
		if(completxAndSimpleSelectArray[i].valueName == valueName){
			bool = true;
			index = i;
			break;
		}
	}
	
	if(bool){
		completxAndSimpleSelectArray[index].value = value;
	}else{
		completxAndSimpleSelectArray.push({valueName:valueName,value:value});
	}
}

//select的简单与复杂的切换
function changeComOrSimFun(){
	for(var m = 0;m<completxAndSimpleSelectArray.length;m++){
		if(completxAndSimpleSelectArray[m].valueName == "ZS"){
			if($('.zsone')){
				$(".zsone option:eq("+Number(completxAndSimpleSelectArray[m].value)+")").prop('selected',true);
			}
			if($('.zstwo')){
				$(".zstwo option:eq("+Number(completxAndSimpleSelectArray[m].value)+")").prop('selected',true);
			}
			if($('.zsthree')){
				$(".zsthree option:eq("+Number(completxAndSimpleSelectArray[m].value)+")").prop('selected',true);
			}
		}else{
			if($('.fxone')){
				$(".fxone option:eq("+Number(completxAndSimpleSelectArray[m].value)+")").prop('selected',true);
			}
			if($('.fxtwo')){
				$(".fxtwo option:eq("+Number(completxAndSimpleSelectArray[m].value)+")").prop('selected',true);
			}
			if($('.fxthree')){
				$(".fxthree option:eq("+Number(completxAndSimpleSelectArray[m].value)+")").prop('selected',true);
			}
		}
	}
	if(dengObj){
		$(".dengone").children("option").each(function() {
			var temp_value = $(this).attr('signalvalue');
			if (temp_value == dengObj.signalvalue) {
				$(this).attr("selected", "selected");
				setLightColor(dengObj.signalvalue, "dengone");
			}
		});
		$(".dengtwo").children("option").each(function() {
			var temp_value = $(this).attr('signalvalue');
			if (temp_value == dengObj.signalvalue) {
				$(this).attr("selected", "selected");
				setLightColor(dengObj.signalvalue, "dengtwo");
			}
		});
		
		var buttonArray = $('.rightButton').find('button');
		for(var i =0;i<buttonArray.length;i++){
			var str = buttonArray[i].getAttribute('onclick')+"";
			var buttonSignalValue = str.split('(')[1].split(')')[0].split(',')[3];
			if(buttonSignalValue == dengObj.signalvalue){
				$(".rightButton button").css("border", "1px solid #FFF");
				$(".rightButton button").css("color", "rgb(255, 255, 255)"); //重置button字颜色为白色
				$('.'+buttonArray[i].getAttribute('class')).css("border", "1px solid rgb(38, 194, 84)"); //点击的Button边框变色
				$('.'+buttonArray[i].getAttribute('class')).css("color", "rgb(38, 194, 84)"); //点击的Button字色
				setLightColor(dengObj.signalvalue, "dengs"); //色灯变色
				$('.'+buttonArray[i].getAttribute('class')).attr("data", "2");
				break;
			}
		}
	}
}

//遮罩层
function MaskIt(obj){
    var hoverdiv = '<div class="divMask" style="position: absolute; width: 1200px; height: 773px; left: 0px; top: 0px; background: #fff; opacity: 0; filter: alpha(opacity=0);z-index:1005;"></div>';
    $(obj).wrap('<div class="position:relative;"></div>');
    $(obj).before(hoverdiv);
    $(obj).data("mask",true);
}
//取消遮罩层
function unMaskIt(obj){
	if($(obj).data("mask") == true){
		$(obj).parent().find(".divMask").remove();
		$(obj).unwrap();
		$(obj).data("mask",false);
	}
	$(obj).data("mask",false);
}

function addAlert(content){
	var content = "<div style='color:black;'>"+content+"</div>";
	BootstrapDialog.show({
		closable:function(){
			$(this).on('click',function(){
				removeLoading();
				window.history.back(-1);
			});
		},
		title: '提示',
		message: content,
		buttons: [{
			icon: 'glyphicon glyphicon-check',
			label: '确定',
			cssClass: 'btn-primary',
			autospin: true,
			action: function () {
				window.history.back(-1);
			}
		}]
	});
}

//获取语音
function playVoice(code, time) {
	if (code) {// 判断返回音效代码是否为空
		var music = $('#bgMusic')[0];
		if (parseInt(code) > 0 && parseInt(time) > 0) {// 开始播放音频
			// console.log("成功：：：：：："+code+"||||"+time);
			// 不重复播放同一个语音
			if (currentVoiceNum != parseInt(code)) {
				// 重置音效播放的次数
				currentPlayTimes = 0;
				// 重置获取到当前音效的信息
				currentVoiceData = {code:code,time:time};
				// 开始播放音效，播放次数为一次的语音之间间隔一秒
				if (time == 1 && currentVoiceNumCopy == parseInt(code)) {
					setTimeout(playVoiceFun, 1000);
				} else {
					playVoiceFun();
				}
				// 记录当前播放音效的code，为了不重复播放用一个音效
				currentVoiceNum = parseInt(code);
				currentVoiceNumCopy = parseInt(code);
			}
		} else {
			// console.log("为0语音"+code+"||||"+time);
			if (!music.paused) {
				music.pause();
				$("#audioBtn").removeClass("play").addClass("pause");
			}
		}
	}
}

// 播放音效
function playVoiceFun(){
	// console.log('开始播放音效');
	var music=$('#bgMusic')[0];
	//音效播放次数加1
	currentPlayTimes++;
	$('#bgMusic').attr('src',"../../textcommon/voice/"+parseInt(currentVoiceData.code)+".mp3");
	music.play();
	$("#audioBtn").removeClass("pause").addClass("play");
}

//监听语音播放完成
function playOver(){
	//console.log("音效播放第"+currentPlayTimes+"次完成");
	//如果播放次数小于当前音效需要的播放的次数，那么再播放一次当前音效
	if(currentPlayTimes<parseInt(currentVoiceData.time)){
		playVoiceFun();
	}else{
		//当前语音播放次数完成后，重置记录的语音code
		if(currentVoiceData.time == 1){
			currentVoiceNum = 0;
		}
	}
}

//记录lkj条件脚本
function sendLKJCondition(content){
	addActionScript("001000",content.outParams);
	addActionScript("007006",content.jianXiuParams);
	addActionScript("007004",content.kaiCheParams);
}

//记录操作脚本,当completeBool为ture时，开发发送到后台
function addActionScript(elementCode,params){
	allActionScript.push({
		elementCode:elementCode,
		params:params
	});
}
